package com.luhaoran.hrm.utils;

/**
 * @author haoranlu
 * @project IntelliJ IDEA
 */

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import javax.servlet.http.HttpServletResponse;
import java.time.LocalDateTime;

/**
 * 试图工具类
 * */
public class ViewUtil {

    public static Object json(HttpServletResponse response, int state, String message) {
        return json(response, state, message, null);
    }

    public static Object json(HttpServletResponse response, int state, String message, Object value) {
        JSONObject objectResult = new JSONObject();
        objectResult.put("state", state);
        if (message != null) {
            objectResult.put("message", message);
        }
        if (value != null) {
            objectResult.put("value", JSON.toJSON(value));
        }
        objectResult.put("timestamp", LocalDateTime.now());
        response.setStatus(state);
        return objectResult;
    }

}

